#include <iostream>
#include <queue>

using namespace std;

const int N = 1e6 + 10;
int n;
int l[N],r[N];

int main(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> l[i] >> r[i];
    }
    queue<int> q;
    q.push(1);
    while(!q.empty()){
        int t = q.front();
        q.pop();
        cout << t << " ";
        if(l[t]) q.push(l[t]);
        if(r[t]) q.push(r[t]);
    }   

    return 0;
}
